import MessageModel from '@/models/message';
import NewsIndexModel from '@/models/newsIndex';
import IndexModel from '@/models/newsIndex';
import messageService from '@/services/MessageService';
import { defaultRenderLogoAndTitle } from '@ant-design/pro-layout/lib/SiderMenu/SiderMenu';
import { action, computed, observable } from 'mobx';
import { message } from 'antd';
export default class MessageStore {

    @observable
    pageSize?: number = 4;
    @observable
    pageNumber?: number = 1;

    @observable
    messageList?: Array<MessageModel>;

    @observable
    messageListLoading: boolean = false;

    @observable
    messageSave?: MessageModel;
    @observable
    messageInfoLoading: boolean = false;
    @observable
    username?: string
    @observable
    email?: string
    @observable
    content?: string

    @action
    async onFinish() {
        let option = {
            username: this.username,
            email: this.email,
            content: this.content,
        };
        const result = await messageService.save(option);
        if (result.isSuccess) {
            message.success("添加成功")

        }
    };



    // @action
    // async saveMesaage(username: string, email: string, content: string) {
    //     let option = {
    //         username: this.username,
    //         email:this.email,
    //         content:this.content,

    //     };
    //     this.messageInfoLoading = true;
    //     this.messageSave = (await messageService.save(option)).dataInfo;
    //     this.messageInfoLoading = false;

    // }
    @action
    async listmessage() {
        this.messageListLoading = true;
        this.messageList = (await messageService.list(this.pageNumber, this.pageSize)).dataList;
        this.messageListLoading = false;
        console.log(this.messageList);

    }
}

export const messageStore = new MessageStore();
